// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   RobotController.java

package jones;

import java.util.*;
import jones.behavior.Arbiter;
import jones.behavior.Behavior;

// Referenced classes of package jones:
//            PortNotConnectedException, AnalogSensor, DigitalSensor, SimObject, 
//            ValueNotAvailableException, Actuator

public class RobotController implements SimObject {
	private class PortArray {

		private List list = null;
		private SortedSet next = null;

		public int add(Object o) {
			if (next.isEmpty()) {
				list.add(o);
				return list.size() - 1;
			} else {
				Integer i = (Integer) next.first();
				list.set(i.intValue(), o);
				next.remove(((Object) (i)));
				return i.intValue();
			}
		}

		public void remove(int i) {
			list.set(i, ((Object) (null)));
			next.add(((Object) (new Integer(i))));
		}

		public Object get(int i) {
			return list.get(i);
		}

		public boolean isConnected(int i) {
			try {
				Object o = list.get(i);
				return o != null;
			} catch (IndexOutOfBoundsException ex) {
				return false;
			}
		}

		private PortArray() {
			list = ((List) (new ArrayList()));
			next = ((SortedSet) (new TreeSet()));
		}

	}

	private PortArray analogSensors = null;
	private PortArray digitalSensors = null;
	private PortArray actuators = null;
	private List behaviors = null;
	private Arbiter arbiter = null;

	public RobotController() {
		analogSensors = new PortArray();
		digitalSensors = new PortArray();
		actuators = new PortArray();
		behaviors = ((List) (new ArrayList()));
	}

	public int addAnalogSensor(AnalogSensor analogSensor) {
		return analogSensors.add(((Object) (analogSensor)));
	}

	public int addDigitalSensor(DigitalSensor digitalSensor) {
		return digitalSensors.add(((Object) (digitalSensor)));
	}

	public void removeAnalogSensor(int port) {
		analogSensors.remove(port);
	}

	public void removeDigitalSensor(int port) {
		digitalSensors.remove(port);
	}

	public int getAnalogSensorValue(int port) throws ValueNotAvailableException {
		if (!analogSensors.isConnected(port)) {
			throw new PortNotConnectedException("port = " + port);
		} else {
			AnalogSensor analogSensor = (AnalogSensor) analogSensors.get(port);
			return analogSensor.getValue();
		}
	}

	public boolean getDigitalSensorValue(int port)
			throws ValueNotAvailableException {
		if (!digitalSensors.isConnected(port)) {
			throw new PortNotConnectedException("port = " + port);
		} else {
			DigitalSensor digitalSensor = (DigitalSensor) digitalSensors.get(port);
			return digitalSensor.getValue();
		}
	}

	public int addActuator(Actuator actuator) {
		return actuators.add(((Object) (actuator)));
	}

	public void removeActuator(int port) {
		actuators.remove(port);
	}

	void addBehavior(Behavior behavior) {
		behaviors.add(((Object) (behavior)));
	}

	void removeBehavior(Behavior behavior) {
		behaviors.remove(((Object) (behavior)));
	}

	void setArbiter(Arbiter arbiter) {
		this.arbiter = arbiter;
	}

	public void update(double time) {
		throw new RuntimeException("update not implemented");
	}
}
